home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.02 Feb 91 / 4th Debugger Appl / 4th Debugger.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  17.2 KB  |  531 lines  |  [TEXT/KAHL]

  1. /************************************************************************/
  2. /*                                                                          */
  3. /*    Source   - 4th Debugger.c                                            */
  4. /*    Author   - Alexander S. Colwell, Copyright © 1990                    */
  5. /*                                                                        */
  6. /*    Purpose     - This application will assist debugging 4th Dimension's    */
  7. /*               external area and related external procedures.            */
  8. /*                                                                        */
  9. /*    Notes    - None.                                                    */
  10. /*                                                                        */
  11. /************************************************************************/
  12.  
  13. #define    DbgExtArea                    /* Mark debugging external area        */
  14. #include "4th Debugger.h"            /* 4th Dimension Debugger defs        */
  15. #include "4th Class.h"                /* 4th Ext Area Class defs            */
  16. #include <StdIO.h>                    /* Standard I/O defs                */
  17. #include "stdarg.h"                    /* Standard Variable Args defs        */
  18. #include <string.h>                    /* String defs                        */
  19.  
  20. pascal void    C4thMain();                /* Define external procedures        */
  21.  
  22. void main()
  23.     {
  24.         gApplication = new(C4thDbgApp);/* Create new application object    */
  25.         gApplication->IApplication(4,4096L,2048L);/* Init application    */
  26.         gApplication->Run();        /* Startup application execution    */
  27.         gApplication->Exit();        /* Return to da "Finder"            */
  28.     }
  29.  
  30. void C4thDbgApp::IApplication(short extraMasters, Size aRainyDayFund,
  31.                                Size aCreditLimit)
  32.     {
  33.         register short    i;            /* Working index                    */
  34.         
  35.         eaDoc = NULL;                /* Mark no external area window        */
  36.         eaIRect.left = eaIRect.top = eaIRect.right = eaIRect.bottom = 0;
  37.         
  38.         for(i = 0; i < 10; i++)        /* Init external procedures            */
  39.             eaProc[i] = NULL;        /* Invalidate external procedure ptr*/
  40.             
  41.         eaName[0] = 0;                /* Null external name string        */
  42.         
  43.                                     /* Continue initialization            */
  44.         inherited::IApplication(extraMasters,aRainyDayFund,aCreditLimit);
  45.  
  46.         InitExtArea();                /* Init external area                */
  47.     }
  48.  
  49. void C4thDbgApp::InstallExtProc(short epIdx, ProcPtr epPtr)
  50.     {
  51.         short    idx = epIdx - ep1;    /* Working ext procedure index        */
  52.         
  53.         if (idx >= 0 && idx < 10)    /* Check if index is valid            */
  54.             eaProc[idx] = epPtr;    /* Install new procedure pointer    */
  55.     }
  56.     
  57. void C4thDbgApp::SetExtArea(short l, short t, short r, short b)
  58.     {
  59.         eaIRect.left = l;            /* Set external rect area            */
  60.         eaIRect.top = t;
  61.         eaIRect.right = r;
  62.         eaIRect.bottom = b;
  63.     }
  64.     
  65. void C4thDbgApp::SetExtName(char *name)
  66.     {
  67.         register long    len;        /* Working string length            */
  68.         
  69.         BlockMove(name,eaName,        /* Copy da string                    */
  70.                   len = min((unsigned char)(*name) + 1,sizeof(eaName)));
  71.         
  72.         eaName[0] = len;            /* Reset to maximum string length    */
  73.     }
  74.     
  75. void C4thDbgApp::CreateDocument(void)
  76.     {
  77.         register CScrollPane *theScrollPane;/* Working scroll pane object*/
  78.         register CDbgPane *theMainPane;/* Working main pane object        */
  79.         Rect    margin;                /* Working margin rect area            */
  80.     
  81.         
  82.         dbgDoc = new(CDbgDoc);        /* Create new document object        */
  83.  
  84.         dbgDoc->IDocument(this,TRUE);/* Do normal initialization        */
  85.         
  86.         dbgDoc->itsWindow = new(CWindow);/* Create new window object    */
  87.         dbgDoc->itsWindow->IWindow(dbgWIND,FALSE,gDesktop,dbgDoc);
  88.         
  89.         theScrollPane = new(CScrollPane);/* Create window's scrolling obj*/
  90.         theScrollPane->IScrollPane(dbgDoc->itsWindow,dbgDoc,10,10,0,0,
  91.                                    sizELASTIC,sizELASTIC,TRUE,TRUE,TRUE);
  92.         theScrollPane->FitToEnclFrame(TRUE,TRUE);
  93.         theMainPane = new(CDbgPane);
  94.         dbgDoc->itsMainPane = theMainPane;
  95.         dbgDoc->itsGopher = theMainPane;
  96.         theMainPane->IEditText(theScrollPane,dbgDoc,
  97.                                1,1,0,0,sizELASTIC,sizELASTIC,432);
  98.         theMainPane->FitToEnclosure(TRUE,TRUE);
  99.         SetRect(&margin,2,2,-2,-2);
  100.         theMainPane->ChangeSize(&margin,FALSE);
  101.         theMainPane->SetFontNumber(monaco);
  102.         theMainPane->SetFontSize(9);
  103.         (*theMainPane->macTE)->crOnly = -1;
  104.         theMainPane->maxChars = maxDbgChars;
  105.         
  106.         theScrollPane->InstallPanorama(theMainPane);
  107.     
  108.         dbgDoc->itsWindow->Select();/* Select our window now!!            */
  109.     }
  110.  
  111. void C4thDbgApp::CreateExtArea(void)
  112.     {
  113.         register CScrollPane *theScrollPane;/* Working scroll pane object*/
  114.         register CEAPane *theMainPane;/* Working main pane object        */
  115.         Rect            wRect;        /* Working rect area                */
  116.         EventRecord        eaEvent;    /* Working event handler            */
  117.  
  118.         eaDoc = new(CDocument);        /* Create 4th ext area document        */
  119.         
  120.         eaDoc->IDocument(this,TRUE);/* Do normal initialization            */
  121.         
  122.         eaDoc->itsWindow = new(CWindow);/* Create new window object        */
  123.         eaDoc->itsWindow->IWindow(eaWIND,FALSE,gDesktop,eaDoc);
  124.         
  125.                                     /* Try and fit ext area within window*/
  126.         wRect = eaDoc->itsWindow->macPort->portRect;
  127.         wRect.right = min(max(wRect.right,
  128.                               wRect.left + max(0,eaIRect.left) +
  129.                               eaIRect.right - eaIRect.left + 32),
  130.                               screenBits.bounds.right - screenBits.bounds.left - 16 + 
  131.                                       eaDoc->itsWindow->macPort->portBits.bounds.left);
  132.         wRect.bottom = min(max(wRect.bottom,
  133.                                wRect.top + max(0,eaIRect.top) + 
  134.                                eaIRect.bottom - eaIRect.top + 32),
  135.                                screenBits.bounds.bottom - screenBits.bounds.top - 16 +
  136.                                        eaDoc->itsWindow->macPort->portBits.bounds.top);
  137.         eaDoc->itsWindow->ChangeSize(wRect.right - wRect.left,
  138.                                       wRect.bottom - wRect.top);
  139.         
  140.         theScrollPane = new(CScrollPane);/* Create window's scrolling obj*/
  141.         theScrollPane->IScrollPane(eaDoc->itsWindow,eaDoc,10,10,0,0,
  142.                                    sizELASTIC,sizELASTIC,TRUE,TRUE,TRUE);
  143.         theScrollPane->FitToEnclFrame(TRUE,TRUE);
  144.         theScrollPane->SetSteps(16,16);
  145.         
  146.         theMainPane = new(CEAPane);    /* Create ext area pane object        */
  147.         eaDoc->itsMainPane = theMainPane;
  148.         eaDoc->itsGopher = theMainPane;
  149.  
  150.         wRect = eaIRect;            /* Set working external rect area    */
  151.         
  152.                                     /* Init external area's pane         */
  153.         theMainPane->IPanorama(theScrollPane,eaDoc,
  154.                   wRect.right - wRect.left + abs(wRect.left) + 16,
  155.                   wRect.bottom - wRect.top + abs(wRect.top) + 16,
  156.                   wRect.left,wRect.top,sizFIXEDSTICKY,sizFIXEDSTICKY);
  157.         theMainPane->FitToEnclosure(TRUE,TRUE);
  158.         theMainPane->SetWantsClicks(TRUE);
  159.         theScrollPane->InstallPanorama(theMainPane);
  160.     
  161.         eaDoc->itsWindow->Select();    /* Select our window now!!            */
  162.  
  163.         theMainPane->eaRect = eaIRect;/* Set rect area                    */
  164.         theMainPane->eaSRect = eaIRect;
  165.         theMainPane->eaObject = NULL;/* Set no external area object        */
  166.  
  167.         eaEvent.what = initEvt;        /* Initialize event record            */
  168.         eaEvent.message = (long)(theMainPane->macPort);
  169.         eaEvent.when = TickCount();
  170.         eaEvent.where.h = eaEvent.where.v = 0;
  171.         eaEvent.modifiers = 0;
  172.         
  173.         theMainPane->DoExtEvent(&eaEvent);/* Do external area event        */
  174.     }
  175.     
  176. void C4thDbgApp::DoCommand(long theCommand)
  177.     {
  178.         switch(theCommand) {        /* Process command                    */
  179.             case cmdAbout:            /* About This dialog                */
  180.                 AboutThis(); break;
  181.                 
  182.             case eaOpen:            /* Open external area                */
  183.                 CreateExtArea(); break;
  184.                 
  185.             case eaDebugger:        /* Hide/Show Debugger                */
  186.                 dbgDoc->itsWindow->ShowOrHide(!dbgDoc->itsWindow->IsVisible());
  187.                 break;
  188.                 
  189.             default:                /* Don't know this command message    */
  190.                 inherited::DoCommand(theCommand);/* Cont cmd processing    */
  191.         }
  192.     }
  193.     
  194. void C4thDbgApp::UpdateMenus(void)
  195.     {
  196.         Str255    wStr;                /* Working string                    */
  197.         
  198.         inherited::UpdateMenus();    /* Update other items                */
  199.         
  200.         if (!eaDoc)                    /* Check if external area not opened*/
  201.             gBartender->EnableCmd(eaOpen);/* Enable "Open External Area"*/
  202.         gBartender->EnableCmd(eaDebugger);/* Enable "Hide/Show Debugger"*/
  203.         
  204.                                     /* Setup "Hide/Show Debugger" item    */
  205.         GetIndString(wStr,eaDebugger,(dbgDoc->itsWindow->IsVisible()?1:2));
  206.         gBartender->SetCmdText(eaDebugger,wStr);
  207.     }
  208.  
  209. void C4thDbgApp::AboutThis(void)
  210.     {
  211.         DialogPtr    dPtr;            /* Working dialog pointer            */
  212.         Point        wPt;            /* Working mouse point                */
  213.         
  214.                                     /* Display "About This..." dialog    */
  215.         if (dPtr = GetNewDialog(atDLOG,(Ptr)(NULL),-1L)) {
  216.             SetPort(dPtr);            /* Set to this dialog port            */
  217.             DrawDialog(dPtr);        /* Draw the items                    */
  218.             while(TRUE)                /* Do until time to quit            */
  219.                 if (Button()) {        /* Check if mouse is down            */
  220.                     GetMouse(&wPt);    /* Get current mouse position        */
  221.                     if (PtInRect(wPt,&dPtr->portRect))/* Inside window?    */
  222.                         break;        /* Let's break-out now!!            */
  223.                 }
  224.             DisposDialog(dPtr);        /* Kill the dialog!!!!                */
  225.             FlushEvents(mDownMask|mUpMask,0);/* Flush all pending events*/
  226.         }
  227.     }
  228.     
  229. void CEAPane::Dispose(void)
  230.     {
  231.         DoSendEvent(deInitEvt);        /* Do external area event            */
  232.         
  233.         gApplication->eaDoc = NULL;    /* Mark no external area window        */
  234.         
  235.         inherited::Dispose();        /* Let's dispose it now                */
  236.     }
  237.     
  238. void CEAPane::UpdateMenus(void)
  239.     {
  240.         inherited::UpdateMenus();    /* Update other items                */
  241.         
  242.         gBartender->EnableCmd(eaClose);/* Enable the items                */
  243.         gBartender->EnableCmd(ep1);
  244.         gBartender->EnableCmd(ep2);
  245.         gBartender->EnableCmd(ep3);
  246.         gBartender->EnableCmd(ep4);
  247.         gBartender->EnableCmd(ep5);
  248.         gBartender->EnableCmd(ep6);
  249.         gBartender->EnableCmd(ep7);
  250.         gBartender->EnableCmd(ep8);
  251.         gBartender->EnableCmd(ep9);
  252.         gBartender->EnableCmd(cmdUndo);
  253.         gBartender->EnableCmd(cmdCut);
  254.         gBartender->EnableCmd(cmdCopy);
  255.         gBartender->EnableCmd(cmdPaste);
  256.         gBartender->EnableCmd(cmdClear);
  257.         gBartender->EnableCmd(eaSelectAll);
  258.     }
  259.     
  260. void    CEAPane::AdjustToEnclosure(Rect *deltaEncl)
  261.     {
  262.         inherited::AdjustToEnclosure(deltaEncl);/* Do normal stuff        */
  263.         FitToEnclosure(TRUE,TRUE);    /* Re-adjust to the window            */
  264.     }
  265.     
  266. void    CEAPane::AdjustCursor(Point where, RgnHandle mouseRgn)
  267.     {
  268.         EventRecord    eaEvent;        /* Working event handler            */
  269.         
  270.         if (!PtInRect(where,&eaSRect))/* Check if inside ext area?        */
  271.             inherited::AdjustCursor(where,mouseRgn);/* Do any other stuff*/
  272.         
  273.         else {                        /* Nope, it's in ext area            */
  274.             
  275.             eaEvent.what = cursorEvt;/* Initialize event record            */
  276.             eaEvent.message = (long)(macPort);
  277.             eaEvent.when = TickCount();
  278.             eaEvent.where = where;
  279.             eaEvent.modifiers = DoGetModifiers();
  280.             
  281.             DoExtEvent(&eaEvent);    /* Do external area event            */
  282.         }
  283.     }
  284.  
  285. void    CEAPane::Dawdle(long *maxSleep)
  286.     {
  287.         inherited::Dawdle(maxSleep);/* Do any other stuff                */
  288.         
  289.         DoSendEvent(nullEvent);        /* Do external area event            */
  290.         
  291.         *maxSleep = 0L;                /* Do it as fast as possible        */
  292.     }
  293.     
  294. void CEAPane::Draw(Rect *area)
  295.     {
  296.         Rect        wRect;            /* Working rect area                */
  297.         
  298.         wRect = *area;                /* Set to working clipping area        */
  299.         FillRect(&wRect,ltGray);    /* Draw into unused area            */
  300.         
  301.         DoSendEvent(updateEvt);        /* Do external area event            */
  302.     }
  303.  
  304. void CEAPane::Scroll(short hDelta, short vDelta, Boolean reDraw)
  305.     {
  306.         OffsetRect(&eaSRect,-hDelta,-vDelta);/* Offset it                */
  307.  
  308.         DoSendEvent(scrollEvt);        /* Do external area event            */
  309.         
  310.         inherited::Scroll(hDelta,vDelta,reDraw);/* OK, let's do it        */
  311.     }
  312.     
  313. void CEAPane::DoClick(Point hitPt, short modifierKeys, long when)
  314.     {
  315.         EventRecord    eaEvent;        /* Working event handler            */
  316.         
  317.         eaEvent.what = mouseDown;    /* Initialize event record            */
  318.         eaEvent.message = (long)(macPort);
  319.         eaEvent.when = when;
  320.         eaEvent.where = hitPt;
  321.         eaEvent.modifiers = modifierKeys;
  322.         
  323.         DoExtEvent(&eaEvent);        /* Do external area event            */
  324.     }
  325.  
  326. void CEAPane::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  327.     {
  328.         EventRecord    eaEvent;        /* Working event handler            */
  329.         
  330.         if (eaObject) {                /* Check if has C4th object            */
  331.             if (eaObject->keyBoardEvents) {/* Check if wants key events    */
  332.                 eaEvent.what = keyDown;/* Initialize event record        */
  333.                 eaEvent.message = theChar | (keyCode << 8);
  334.                 eaEvent.when = macEvent->when;
  335.                 eaEvent.where = lastWhere;
  336.                 eaEvent.modifiers = macEvent->modifiers;
  337.                 
  338.                 DoExtEvent(&eaEvent);/* Do ext area event                */
  339.             }
  340.         }
  341.     }
  342.     
  343. void CEAPane::DoAutoKey(char theChar, Byte keyCode, EventRecord *macEvent)
  344.     {
  345.         DoKeyDown(theChar,keyCode,macEvent);/* Pass it on!                */
  346.     }
  347.  
  348. void CEAPane::Activate(void)
  349.     {
  350.         inherited::Activate();        /* Do other stuff first                */
  351.  
  352.         if (eaObject)                /* Check if has C4th object            */
  353.             if (eaObject->keyBoardEvents)/* Check if want activate evts    */
  354.                 DoSendEvent(activNote);/* Send message                    */
  355.     }
  356.  
  357. void CEAPane::Deactivate(void)
  358.     {
  359.         if (gApplication->eaDoc)    /* Check if not quitting            */
  360.             if (eaObject)            /* Check if has C4th object            */
  361.                 if (eaObject->keyBoardEvents)/* Want deactivate events    */
  362.                     DoSendEvent(deActivNote);/* Send message            */
  363.  
  364.         inherited::Deactivate();    /* Do other stuff first                */
  365.     }
  366.  
  367. void CEAPane::DoCommand(long theCommand)
  368.     {
  369.         switch(theCommand) {        /* Process command                    */
  370.             case cmdUndo:            /* Edit "Undo" event                */
  371.                 DoSendEvent(undoEvt); break;
  372.                 
  373.             case cmdCut:            /* Edit "Cut" event                    */
  374.                 DoSendEvent(cutEvt); break;
  375.                 
  376.             case cmdCopy:            /* Edit "Copy" event                */
  377.                 DoSendEvent(copyEvt); break;
  378.                 
  379.             case cmdPaste:            /* Edit "Paste" event                */
  380.                 DoSendEvent(pasteEvt); break;
  381.                 
  382.             case cmdClear:            /* Edit "Clear" event                */
  383.                 DoSendEvent(clearEvt); break;
  384.                 
  385.             case eaSelectAll:        /* Edit "Select All" event            */
  386.                 DoSendEvent(selectAllEvt); break;
  387.                 
  388.             case eaClose:            /* Close External Area                */
  389.                 inherited::DoCommand(cmdClose); break;
  390.                 
  391.             case ep1:                /* Execute External Procedure # 1    */
  392.             case ep2:                /* Execute External Procedure # 2    */
  393.             case ep3:                /* Execute External Procedure # 3    */
  394.             case ep4:                /* Execute External Procedure # 4    */
  395.             case ep5:                /* Execute External Procedure # 5    */
  396.             case ep6:                /* Execute External Procedure # 6    */
  397.             case ep7:                /* Execute External Procedure # 7    */
  398.             case ep8:                /* Execute External Procedure # 8    */
  399.             case ep9:                /* Execute External Procedure # 9    */
  400.                 DoExtProc(theCommand - ep1); break;
  401.                 
  402.             default:                /* None of these, let's inherit        */
  403.                 inherited::DoCommand(theCommand);/* Cont cmd processing    */
  404.         }
  405.     }
  406.     
  407. void CEAPane::DoSendEvent(short theCommand)
  408.     {
  409.         EventRecord    eaEvent;        /* Working event handler            */
  410.         WindowPtr    wPtr = eaObject->wPtr;/* Working window pointer        */
  411.         
  412.         if (printing)                /* Check if printing                */
  413.             GetPort(&wPtr);            /* Get current print port            */
  414.             
  415.         eaEvent.what = theCommand;    /* Initialize event record            */
  416.         eaEvent.message = (long)(wPtr);
  417.         eaEvent.when = TickCount();
  418.         eaEvent.where = lastWhere;
  419.         eaEvent.modifiers = DoGetModifiers();
  420.         
  421.         DoExtEvent(&eaEvent);        /* Do external area event            */
  422.     }
  423.     
  424. void CEAPane::DoExtEvent(EventRecord *theEvent)
  425.     {
  426.         C4th    *wObject;            /* Working ext area object            */
  427.         Str255    wName;                /* Working ext area name            */
  428.         Rect    wRect;                /* Working ext rect area            */
  429.         
  430.         Prepare();                    /* Prepare for possible drawing        */
  431.         
  432.         lastWhere = theEvent->where;/* Save last know "where" point        */
  433.         
  434.         wRect = eaRect;                /* Set external rect area            */
  435.         wObject = eaObject;            /* Set external area object handle    */
  436.         BlockMove(gApplication->eaName,wName,/* Copy external name        */
  437.                   (long)(gApplication->eaName[0]));
  438.                   
  439.         C4thMain(theEvent,&wRect,wName,&wObject);/* Perform update        */
  440.         
  441.         eaObject = wObject;            /* Reset external area object handle*/
  442.     }
  443.  
  444. void CEAPane::DoExtProc(short epIdx)
  445.     {
  446.         C4th    *wObject;            /* Working 4th object                */
  447.         
  448.         if (gApplication->eaProc[epIdx]) {/* Check if it's valid        */
  449.             wObject = eaObject;        /* Copy ext area object                */
  450.             (*gApplication->eaProc[epIdx])(&wObject);/* Pipe it on        */
  451.             eaObject = wObject;        /* Resave ext area object            */
  452.         }
  453.     }
  454.     
  455. short CEAPane::DoGetModifiers(void)
  456.     {
  457.         KeyMap        keyMap;            /* Working key map                    */
  458.         register short modifiers = 0;/* Working modifiers                */
  459.         
  460.         GetKeys(&keyMap);            /* Get the key map status            */
  461.         
  462.         if (keyMap.Key[1] & 0x00000001L)/* Check if got "shift" key        */
  463.             modifiers |= shiftKey;    /* Set "shift" key modifier            */
  464.             
  465.         if (keyMap.Key[1] & 0x00000004L)/* Check if got "option" key    */
  466.             modifiers |= optionKey;    /* Set "option" key    modifier        */
  467.             
  468.         if (keyMap.Key[1] & 0x00008000L)/* Check if got "command" key    */
  469.             modifiers |= cmdKey;    /* Set "command" key    modifier    */
  470.             
  471.         if (keyMap.Key[1] & 0x00000002L)/* Check if got "caps lock" key    */
  472.             modifiers |= alphaLock;    /* Set "caps lock" key    modifier    */
  473.             
  474.         if (!Button())                /* Check if mouse button is up        */
  475.             modifiers |= btnState;    /* Set button state                    */
  476.             
  477.         return(modifiers);            /* Return key's modifiers            */
  478.     }
  479.     
  480. Boolean CDbgDoc::Close(Boolean quitting)
  481.     {
  482.         register Boolean status = FALSE;/* Closing status indicator        */
  483.  
  484.         if (quitting) {                /* Check if quitting                */
  485.             itsWindow->ShowOrHide(TRUE);/* Let's show it before closing    */
  486.             status = inherited::Close(quitting);/* Continue closing        */
  487.         }
  488.         else                        /* Nope, simply hiding da window    */
  489.             itsWindow->ShowOrHide(FALSE);/* Let's hide it only            */
  490.             
  491.         return(status);                /* Return status indicator            */
  492.     }
  493.     
  494. void CDbgPane::DoPrint(fmt,args)
  495.     char    *fmt;
  496.     va_list    args;
  497.     {
  498.         register short    i;            /* Working index                    */
  499.         char    buffer[512];        /* Working print output stream buffer*/
  500.         register long    bufferLen;    /* Working output stream length        */
  501.         
  502.         vsprintf(buffer,fmt,&args);    /* Copy into output stream buffer    */
  503.         
  504.         bufferLen = strlen(buffer);    /* Get output stream buffer length    */
  505.         
  506.         for(i = 0; i < bufferLen; i++)/* Convert special characters        */
  507.             switch(buffer[i]) {        /* Process this character            */
  508.                 case '\t': buffer[i] = ' '; break;
  509.                 case '\n': buffer[i] = '\r'; break;
  510.             }
  511.             
  512.         Prepare();                    /* Prepare for drawing                */
  513.         
  514.                                     /* Check if text buffer too big        */
  515.         if ((*macTE)->teLength + bufferLen > maxChars)
  516.             for(i = 0; (*macTE)->nLines; i++)
  517.                 if ((*macTE)->lineStarts[i] > bufferLen) {
  518.                     TESetSelect(0L,(long)((*macTE)->lineStarts[i] - 1),macTE);
  519.                     TEDelete(macTE);
  520.                 }
  521.         
  522.                                     /* Set it to the end of text buffer    */
  523.         TESetSelect((long)((*macTE)->teLength),(long)((*macTE)->teLength),
  524.                     macTE);
  525.                     
  526.         TEInsert(buffer,bufferLen,macTE);/* Insert text stream            */
  527.         
  528.         AdjustBounds();                /* Re-adjust the boundaries            */
  529.         ScrollToSelection();        /* Scroll to the cursor location    */
  530.     }
  531.